﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EggTimer.Parsers;

namespace EggTimer
{
    public class ETimer
    {
        private int mSeconds;
        public int Seconds
        {
            get { return mSeconds; }
            set { mSeconds = value; }
        }

        private int mMinutes;
        public int Minutes
        {
            get { return mMinutes; }
            set { mMinutes = value; }
        }

        private int mHours;
        public int Hours
        {
            get { return mHours; }
            set { mHours = value; }
        }

        public string SSeconds
        {
            get { return padNumber(mSeconds); }
        }

        public string SMinutes
        {
            get { return padNumber(mMinutes); }
        }

        public string SHours
        {
            get { return padNumber(mHours); }
        }

        public int TotalSeconds
        {
            get
            {
                int value = mSeconds;
                value += (mHours * 60 * 60);
                value += (mMinutes * 60);
                return value;
            }
        }

        public ETimer()
        {

        }

        public ETimer(string value)
        {
            mHours = TimeParser.getHours(value);
            mMinutes = TimeParser.getMinutes(value);
            mSeconds = TimeParser.getSeconds(value);
        }

        public ETimer(int hours, int minutes, int seconds)
        {
            mHours = hours;
            mMinutes = minutes;
            mSeconds = seconds;
        }

        public void Increment()
        {
            mSeconds++;
            if (mSeconds > 59)
            {
                mSeconds = 0;
                mMinutes++;
                if (mMinutes > 59)
                {
                    mMinutes = 0;
                    mHours++;
                }
            }
        }

        public void Decrement()
        {
            mSeconds--;
            if (mSeconds < 0)
            {
                mSeconds = 59;
                mMinutes--;
                if (mMinutes < 0)
                {
                    mMinutes = 59;
                    mHours--;
                }
            }
        }

        private string padNumber(int value)
        {
            if (value < 10)
            {
                return Convert.ToString("0" + value);
            }
            return Convert.ToString(value);
        }
    }
}
